package com.foftact.etfweekly;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONWriter;
import com.foftact.Foftact;
import com.foftact.etfrank.ETFRank;
import com.foftact.etfrank.service.ETFRankService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.util.List;

@SpringBootTest(classes= Foftact.class)
public class ETFWeeklyTestng extends AbstractTestNGSpringContextTests {

    @Autowired
    private ETFWeeklyService etfWeeklyService;

    @Autowired
    ETFRankService etfRankService;

    @Test
    public void test_one() throws Exception {
        etfWeeklyService.fetchAndSaveETFWeeklyData("159915");
        List<ETFWeekly> list = etfWeeklyService.getRecentETFWeeklyByCode("159915", 20);
        System.out.println(JSON.toJSONString(list,  JSONWriter.Feature.PrettyFormat));
        Assert.assertEquals(list.size(), 20);
    }

    @Test
    public void test_all() throws Exception {
        List<ETFRank> etfRanks = etfRankService.getETFRankByGrowthRate(StringUtils.EMPTY, StringUtils.EMPTY, 10000);
        for (ETFRank etfRank : etfRanks) {
            etfWeeklyService.fetchAndSaveETFWeeklyData(etfRank.getFundCode());
            List<ETFWeekly> list = etfWeeklyService.getRecentETFWeeklyByCode("159915", 20);
            System.out.println(JSON.toJSONString(list,  JSONWriter.Feature.PrettyFormat));
            Assert.assertEquals(list.size(), 20);
        }

    }

}
